namespace FormsAnywhere.UIProcessDesigner
{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Collections.Specialized;
    using Microsoft.VisualStudio.Modeling.Validation;

    [ValidationState(ValidationState.Enabled)]
    public partial class FormAction
    {
        // Validation methods for FormAction go here.

        // This attribute identifies the method ValidateActionType 
        // to the validation framework.
        [ValidationMethod
         ( // These values select which events cause the method to be invoked.
            ValidationCategories.Open |
             ValidationCategories.Save |
              ValidationCategories.Menu
         )
        ]
        // This method is applied to each instance of the 
        // type in a model. 
        private void ValidateActionType(ValidationContext context)
        {
            if((!this.ActionType.Equals("SaveToDisk")) &&
                (!this.ActionType.Equals("SendToWebService")) &&
                (!this.ActionType.Equals("None")) &&
                (!this.ActionType.Equals("LoadNewForm")))
                {
                    context.LogError(
                        // Description
                                 "ActionType must be one of the following: None, SaveToDisk, SendToWebService or LoadNewForm",
                        // Unique code for this error
                                 "FAW001FormActionError",
                        // Objects to select when user double-clicks error
                                 this);
                }
        }

        // This attribute identifies the method ValidateEndPoint 
        // to the validation framework.
        [ValidationMethod
         ( // These values select which events cause the method to be invoked.
             ValidationCategories.Open |
             ValidationCategories.Save |
              ValidationCategories.Menu
         )
        ]
        // This method is applied to each instance of the 
        // type in a model. 
        private void ValidateEndPoint(ValidationContext context)
        {
            if (((this.ActionType.Equals("SendToWebService")) ||
                (this.ActionType.Equals("LoadNewForm"))) &&
                (this.EndPoint.Length <=0 ))
            {
                context.LogError(
                    // Description
                             "EndPoint must have a value for ActionTypes of SendToWebService or LoadNewForm",
                    // Unique code for this error
                             "FAW002FormActionError",
                    // Objects to select when user double-clicks error
                             this);
            }
        }
    }
}
